package June;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class RemainingDaysToBirthday {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Calendar current = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        System.out.print("请输入你的生日（格式：yyyy-MM-dd）：");
        String birthdayInput = scanner.nextLine();

        try {
            Date birthday = sdf.parse(birthdayInput);
            Calendar userBirthday = Calendar.getInstance();
            userBirthday.setTime(birthday);

            int currentYear = current.get(Calendar.YEAR);
            userBirthday.set(Calendar.YEAR, currentYear); // 确保与当前年份相同

            boolean isBirthdayThisYear = currentYear == userBirthday.get(Calendar.YEAR);

            if (isBirthdayThisYear) {
                if (userBirthday.after(current)) {
                    int remainingDays = (userBirthday.get(Calendar.DAY_OF_YEAR) - current.get(Calendar.DAY_OF_YEAR));
                    System.out.println("距离今年的生日还有 " + remainingDays + " 天。");
                } else {
                    System.out.println("你的生日已经过了。");
                }
            } else {
                System.out.println("你的生日不在今年。");
            }
        } catch (ParseException e) {
            System.out.println("错误的日期格式，请输入正确的日期格式：yyyy-MM-dd。例如：1990-12-31");
        } finally {
            scanner.close(); // 关闭 Scanner 对象
        }
    }
}